#!/usr/bin/python3
import os,getopt
import sys
"""
删除指定后缀类型，大小限制的文件
"""

def getSpecifiedTypeFileFromDirectory(file_dir):
    """
    获取路径下所有具某些指定后缀的图片
    :param file_dir: 根路径
    :return:
    """

    for dirpath, dirnames, filenames in os.walk(file_dir):
        for file in filenames:
            currentPath = os.path.join(dirpath, file)
            del_small_file(currentPath)

 


def del_small_file(file_name):
    size = os.path.getsize(file_name)
    file_size = 0
    if size == file_size: #指定大小
        print('remove',size,file_name)
        os.remove(file_name)

def main(argv):
    dec = """用于删除目录下的空文件，大小为0"""

    flag = 0
    try:
      opts, args = getopt.getopt(argv,"-p:-h",["path=","help"])
    except getopt.GetoptError:
      print 
      sys.exit(2)

    for opt, arg in opts:
        if opt in ('-h','--help'):
            print("说明:")
            exit(0)
        elif opt in ("-p", "--path"):
            path = arg
            getSpecifiedTypeFileFromDirectory(path)
            exit(0)



if __name__ == "__main__":
   main(sys.argv[1:])








